import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:lib_uikit/extension/gt_image_extension.dart';
import 'package:lib_uikit/theme/gt_colors_v3.dart';

class GTBackButton extends StatelessWidget {
  final VoidCallback? onPressed;
  final Color? color;
  final Widget? backIcon;

  const GTBackButton({Key? key, this.color, this.onPressed, this.backIcon}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        if (onPressed != null) {
          onPressed!();
        } else {
          if (Navigator.of(context).canPop()) {
            Navigator.of(context).pop();
          } else {
            SystemNavigator.pop(animated: true);
          }
        }
      },
      child: Container(
        padding: const EdgeInsets.all(12),
        alignment: Alignment.center,
        child: backIcon ??
            Image.asset(
              'assets/images/uikit_btn_back.png'.themePath(maybeRTL: true),
              color: color ?? GTColorsV3.uikitIcon1V3.color,
              package: 'lib_uikit',
              height: 20,
              fit: BoxFit.fitHeight,
            ),
      ),
    );
  }
}
